package com.atguigu.lease.exception;

import com.atguigu.lease.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 51560
 * @project lease
 * @title 全局异常处理器
 * @package com.atguigu.lease.exception
 * @since 2025/5/9 16:32
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(LeaseException.class)
    public Result<Object> removeApartmentException(LeaseException e) {
        return Result.build(e.getMessage(), e.getCode());
    }

    @ExceptionHandler(Exception.class)
    public Result<Object> handleException(Exception e) {
        System.out.println(e.getMessage());
        return Result.fail();
    }

}
